package com.macro.mall.portal.config;

import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @ClassName WxPayAutoCertificateConfig
 * @Package com.macro.mall.portal.config
 * @Description TODO
 * @Author wsx
 * @Date 2024/8/719:16
 * @Version V1.0
 * @Copyright yunshan
 */
@Configuration
public class WxPayAutoCertificateConfig {

    @Resource
    private WxPayConfig wxPayConfig;

    /**
     * 初始化商户配置
     * @return
     */
    @Bean
    public RSAAutoCertificateConfig rsaAutoCertificateConfig() {
        String privateKeyPath = System.getProperty("user.dir")+"/wechat/cert/apiclient_key.pem";
        RSAAutoCertificateConfig config = new RSAAutoCertificateConfig.Builder()
                .merchantId(wxPayConfig.getMerchantId())
                .privateKeyFromPath(privateKeyPath)
                .merchantSerialNumber(wxPayConfig.getMerchantSerialNumber())
                .apiV3Key(wxPayConfig.getApiV3Key())
                .build();
        return config;
    }
}
